3D Graphics Programming with QuickDraw 3D 1.5.4
Previous | QD3D Book | Overview | Chapter Contents | Next |
A draw context contains information that is specific to a particular type of window system, such as the extent of the pane to draw into and the method of clearing the window. You need to create a draw context and add it to a view in order to render a model. Listing 7 illustrates how to create a draw context for drawing into Macintosh windows.
Listing 7 Creating a Macintosh draw context
TQ3DrawContextObject MyNewDrawContext (WindowPtr theWindow)
{
TQ3DrawContextObject myDrawContext;
TQ3DrawContextData myDrawContextData;
TQ3MacDrawContextData myMacDrawContextData;
TQ3ColorARGB myClearColor;
/*Set the background color.*/
Q3ColorARGB_Set(&myClearColor, 1.0, 0.6, 0.9, 0.9);
/*Fill in draw context data.*/
myDrawContextData.clearImageMethod = kQ3ClearMethodWithColor;
myDrawContextData.clearImageColor = myClearColor;
myDrawContextData.paneState = kQ3False;
myDrawContextData.maskState = kQ3False;
myDrawContextData.doubleBufferState = kQ3True;
/*Fill in Macintosh-specific draw context data.*/
myMacDrawContextData.drawContextData = myDrawContextData;
myMacDrawContextData.window = (CWindowPtr) theWindow;
myMacDrawContextData.library = kQ3Mac2DLibraryNone;
myMacDrawContextData.viewPort = NULL;
myMacDrawContextData.grafPort = NULL;
/*Create draw context.*/
myDrawContext = Q3MacDrawContext_New(&myMacDrawContextData);
return (myDrawContext);
}
Essentially, MyNewDrawContext just fills in the fields of a TQ3MacDrawContextData structure and calls Q3MacDrawContext_New to create a new Macintosh draw context.
Previous | QD3D Book | Overview | Chapter Contents | Next |